// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class PipeControl extends cc.Component {

    @property
    speed: number = 4;

    @property
    width: number = 288;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start () {

    }

    radomY(){
        // 生成一个 -300 - 300 的随机值
        return Math.random() * 170 - 10;
    }

    update (dt) {
        for (let pipe of this.node.children) {
            pipe.x -= this.speed * dt;
            if (pipe.x < -190) {
                pipe.x += this.width * 2;
                pipe.y = this.radomY();
            }
        }
    }
}
